﻿using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using Microsoft.SqlServer.Server;

public partial class _Default : System.Web.UI.Page 
{
    static List<Gia> listgia=new List<Gia>();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }
    }
    public void Bind()
    {
        listgia = HoadonBLL.giaselect();
        DdlSoluongthe.DataSource = listgia;
        DdlSoluongthe.DataValueField = "soluong";
        DdlSoluongthe.DataBind();
        lblTongtien.Text = listgia[0].Tongtien + ".000 VND";
    }
    protected void DdlSoluongthe_SelectedIndexChanged(object sender, EventArgs e)
    {
        lblsoluonthe.Text = listgia[Convert.ToInt32(DdlSoluongthe.Text)-1].Soluong.ToString() + " x ";
        lblgia.Text = listgia[Convert.ToInt32(DdlSoluongthe.Text)-1].Giathe.ToString() + " = ";
        lblTongtien.Text = listgia[Convert.ToInt32(DdlSoluongthe.Text)].Tongtien.ToString() + ".000 VND";
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Donhang donhang = new Donhang();
        donhang.Tennguoinhanthe = txtTennguoinhan.Text;
        donhang.Diachinguoinhanthe = txtDiachinhanthe.Text;
        donhang.Tinhthanhpho = DdlTinhthanhpho.Text;
        donhang.Sodienthoai = txtSodienthoai.Text;
        donhang.Diachiemail = txtDiachiemail.Text;
        donhang.Soluongthe = Convert.ToInt32(DdlSoluongthe.Text);
        donhang.Tongtien = lblTongtien.Text;
        int a = HoadonBLL.DonhangInsert(donhang);
        Response.Write(a.ToString());
    }

}
